package com.tacx.groupassignment;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {
	ViewPager Tab;
	TabPagerAdapter TabAdapter;
	ActionBar actionBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
		Tab = (ViewPager) findViewById(R.id.pager);
		Tab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
			@Override
			public void onPageSelected(int position) {
				actionBar = getActionBar();
				actionBar.setSelectedNavigationItem(position);
			}
		});
		Tab.setAdapter(TabAdapter);
		actionBar = getActionBar();
		// Enable Tabs on Action Bar
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		ActionBar.TabListener tabListener = new ActionBar.TabListener() {
			@Override
			public void onTabReselected(android.app.ActionBar.Tab tab,
					FragmentTransaction ft) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
				Tab.setCurrentItem(tab.getPosition());
			}

			@Override
			public void onTabUnselected(android.app.ActionBar.Tab tab,
					FragmentTransaction ft) {
				// TODO Auto-generated method stub
			}
		};
		// Add New Tab
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_arkitektur)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_brugere)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_energidesign)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_industrialisering)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_okonomi)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_stabilitet)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_stedet)
				.setTabListener(tabListener));
		actionBar.addTab(actionBar.newTab().setText(R.string.category_title_tekniske_installationer)
				.setTabListener(tabListener));
	}
	
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.main, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
//	        case R.id.action_add_brick:
//	            showMessageBox();
//	            return true;
//	        case R.id.action_about:
//	            showAbout();
//	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
	
}
